package org.dizena.cola.starter;

import lombok.extern.slf4j.Slf4j;
import org.dizena.cola.starter.service.ExecuteService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.ResourceBundle;

@Slf4j
@SpringBootApplication
public class StartFlywayApplication {
    public static void main(String[] args) {
       try{
           InputStream in = 	StartFlywayApplication.class
                   .getClassLoader()
                   .getResourceAsStream("config.properties");
           Properties ps = new Properties();
           ps.load(in);
           log.info(ps.getProperty("project")+","+ps.getProperty("action")+","+ps.getProperty("version"));
           ResourceBundle config = ResourceBundle.getBundle("config");
           log.info(config.getString("project")+","+config.getString("action")+","+config.getString("version"));
       }catch (IOException e){

       }

        log.info("服务启动...");
        ConfigurableApplicationContext context = SpringApplication.run(StartFlywayApplication.class, args);
        String project = "basic";
        String action = "migrate";
        String version = "V1.1";

        ExecuteService service = context.getBean(ExecuteService.class);
        service.execute(project, action, version);
        log.info("服务停止...");
        context.close();
    }
}
